<?php

/**
 * Application Models
 *
 * @package Application_Model
 * @subpackage Model
 * @author lucho
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */


/**
 * 
 *
 * @package Application_Model
 * @subpackage Model
 * @author lucho
 */
class Application_Model_PermisoRol extends Application_Model_ModelAbstract
{

    /**
     * Database var type int(10) unsigned
     *
     * @var int
     */
    protected $_CodigoPermiso;

    /**
     * Database var type int(10) unsigned
     *
     * @var int
     */
    protected $_CodigoRol;


    /**
     * Parent relation permiso_rol_ibfk_1
     *
     * @var Application_Model_Permiso
     */
    protected $_Permiso;

    /**
     * Parent relation permiso_rol_ibfk_2
     *
     * @var Application_Model_Rol
     */
    protected $_Rol;


    /**
     * Sets up column and relationship lists
     */
    public function __construct()
    {
        parent::init();
        $this->setColumnsList(array(
            'codigo_permiso'=>'CodigoPermiso',
            'codigo_rol'=>'CodigoRol',
        ));

        $this->setParentList(array(
            'PermisoRolIbfk1'=> array(
                    'property' => 'Permiso',
                    'table_name' => 'Permiso',
                ),
            'PermisoRolIbfk2'=> array(
                    'property' => 'Rol',
                    'table_name' => 'Rol',
                ),
        ));

        $this->setDependentList(array(
        ));
    }

    /**
     * Sets column codigo_permiso
     *
     * @param int $data
     * @return Application_Model_PermisoRol
     */
    public function setCodigoPermiso($data)
    {
        $this->_CodigoPermiso = $data;
        return $this;
    }

    /**
     * Gets column codigo_permiso
     *
     * @return int
     */
    public function getCodigoPermiso()
    {
        return $this->_CodigoPermiso;
    }

    /**
     * Sets column codigo_rol
     *
     * @param int $data
     * @return Application_Model_PermisoRol
     */
    public function setCodigoRol($data)
    {
        $this->_CodigoRol = $data;
        return $this;
    }

    /**
     * Gets column codigo_rol
     *
     * @return int
     */
    public function getCodigoRol()
    {
        return $this->_CodigoRol;
    }

    /**
     * Sets parent relation CodigoPermiso
     *
     * @param Application_Model_Permiso $data
     * @return Application_Model_PermisoRol
     */
    public function setPermiso(Application_Model_Permiso $data)
    {
        $this->_Permiso = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['codigo_permiso'];
        }

        $this->setCodigoPermiso($primary_key);

        return $this;
    }

    /**
     * Gets parent CodigoPermiso
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Permiso
     */
    public function getPermiso($load = true)
    {
        if ($this->_Permiso === null && $load) {
            $this->getMapper()->loadRelated('PermisoRolIbfk1', $this);
        }

        return $this->_Permiso;
    }

    /**
     * Sets parent relation CodigoRol
     *
     * @param Application_Model_Rol $data
     * @return Application_Model_PermisoRol
     */
    public function setRol(Application_Model_Rol $data)
    {
        $this->_Rol = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['codigo_rol'];
        }

        $this->setCodigoRol($primary_key);

        return $this;
    }

    /**
     * Gets parent CodigoRol
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Rol
     */
    public function getRol($load = true)
    {
        if ($this->_Rol === null && $load) {
            $this->getMapper()->loadRelated('PermisoRolIbfk2', $this);
        }

        return $this->_Rol;
    }

    /**
     * Returns the mapper class for this model
     *
     * @return Application_Model_Mapper_PermisoRol
     */
    public function getMapper()
    {
        if ($this->_mapper === null) {
            $this->setMapper(new Application_Model_Mapper_PermisoRol());
        }

        return $this->_mapper;
    }

    /**
     * Deletes current row by deleting the row that matches the primary key
     *
	 * @see Application_Model_Mapper_PermisoRol::delete
     * @return int|boolean Number of rows deleted or boolean if doing soft delete
     */
    public function deleteRowByPrimaryKey()
    {
        $primary_key = array();
        if (! $this->getCodigoPermiso()) {
            throw new Exception('Primary Key CodigoPermiso does not contain a value');
        } else {
            $primary_key['codigo_permiso'] = $this->getCodigoPermiso();
        }

        if (! $this->getCodigoRol()) {
            throw new Exception('Primary Key CodigoRol does not contain a value');
        } else {
            $primary_key['codigo_rol'] = $this->getCodigoRol();
        }

        return $this->getMapper()->getDbTable()->delete('codigo_permiso = '
                    . $this->getMapper()->getDbTable()->getAdapter()->quote($primary_key['codigo_permiso'])
                    . ' AND codigo_rol = '
                    . $this->getMapper()->getDbTable()->getAdapter()->quote($primary_key['codigo_rol']));
    }
}
